package com.mes.web.controller.llm.Task;

import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.support.WebApplicationContextUtils;

import com.mes.service.llm.ChartLlmService;
import com.mes.service.warning.WarningService;

/**
 * 
 * @Title:RankTaskListener
 * @Package com.mes.web.controller.llm.Task
 * @author llm
 * @date 2019年6月6日
 * @version 1.0
 */
public class RankTaskListener implements ServletContextListener{

	Timer timer = null;
	/**       
	 * 监听任务
	 * @param sce    
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		//通过工具类获取spring容器的引用
		ChartLlmService chartLlmService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(ChartLlmService.class);
		WarningService warningService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(WarningService.class);
		timer = new Timer(true);
		//参数内容（1、定时任务类的带参构造函数，2、项目启动后延迟多久执行任务，3、任务间隔多久再次执行）
		timer.schedule(new RankTask(chartLlmService, warningService), 0, 24 * 60 * 60 * 1000);
	}

	/**       
	 * @param sce    
	 */
	@Override
	public void contextDestroyed(ServletContextEvent sce) {

	}

}
